function changeLinks(data, baseUrl:string) {
  const obj = data.items[0];
  const result = [];
  const isItems = obj.items.filter(
    (item) => !item.link && item.items && item.items.length > 0
  );
  const isLinks = obj.items.filter((item) => item.link && !item.items);
  if (isLinks.length > 0) {
    result.push({
      name: obj.text,
      dataSource: obj,
      length: obj.items.length,
      path: baseUrl
        ? baseUrl.substring(0,baseUrl.length-1) + data.base + "" + isLinks[0].link
        : data.base + "" + isLinks[0].link,
    });
  }

  if (isItems.length > 0) {
    isItems.forEach((element) => {
      result.push(...changeLinks(element, baseUrl));
    });
  }
  return result;
}

export default (list, baseUrl) => {
  const keys: string[] = Reflect.ownKeys(list) as string[];
  const result = [];
  keys.forEach((item) => {
    const data = list[item];
    if (data.items && data.items.length > 0) {
      result.push(...changeLinks(data, baseUrl));
    }
  });
  return result;
};
